﻿using DataAccess.Exceptions;
using Model;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Business.WPF
{
    public class SearchSubjectManager
    {
        public Collection<Subject> SearchByName(String nameSubject, bool onlyActive)
        {
            try
            {
                if (String.IsNullOrEmpty(nameSubject))
                {
                    return (DataAccess.SubjectDataAccess.getAll(onlyActive));
                }
                else
                {
                    return (DataAccess.SubjectDataAccess.getSubjectByName(nameSubject, onlyActive));
                }
            }
            catch (Exception exception)
            {
                throw new BusinessException("Error: " + exception.Message);
            }
        }

        public Collection<Subject> SearchByCode(String code, bool onlyActive)
        {
            try
            {
                if (String.IsNullOrEmpty(code))
                {
                    return (DataAccess.SubjectDataAccess.getAll(onlyActive));
                }
                else
                {
                    return (DataAccess.SubjectDataAccess.getSubjectLikeByCode(code, onlyActive));
                }
            }
            catch (Exception exception)
            {
                throw new BusinessException("Error: " + exception.Message);
            }
        }

        public Collection<Subject> SearchByAcronym(String acronym, bool onlyActive)
        {
            try
            {
                if (String.IsNullOrEmpty(acronym))
                {
                    return (DataAccess.SubjectDataAccess.getAll(onlyActive));
                }
                else
                {
                    return (DataAccess.SubjectDataAccess.getSubjectByAcronym(acronym, onlyActive));
                }
            }
            catch (Exception exception)
            {
                throw new BusinessException("Error: " + exception.Message);
            }
        }
    }
}
